//
//  TouchView.m
//  UI29_Block
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "TouchView.h"

@interface TouchView ()

@property (strong, nonatomic) IBOutlet UIView *View;
@property (nonatomic, copy) void (^block) (TouchView *);
@property (nonatomic, copy) void (^deleBtnHandle)(UIButton *);
@property (nonatomic, copy) void (^editBtnHandle)(UIButton *);
@end

@implementation TouchView


- (instancetype) initWithCoder:(NSCoder *)aDecoder {
    
    self = [super initWithCoder:aDecoder];
    
    if (self) {
        
        [[NSBundle mainBundle] loadNibNamed:@"TouchView" owner:self options:nil];
        
        self.View.frame = self.bounds;
        
        [self addSubview:self.View];
        
    }
    
    return self;
    
    
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

// 点击之后调用 block
    
    self.block(self);
    NSLog(@"1");

}

// 实现带 block 参数的方法
-(void)viewDidClick:(void (^)(TouchView *))block {

    self.block = block;
    NSLog(@"2");
    
}
/** 点击删除 block */
- (IBAction)handleButtonAction:(id)sender {
    
    // 修改 sender ,拖空间的时候没有修改,通过此修改
    self.deleBtnHandle((UIButton *)sender);
    
}

/**点击编辑 block */
- (IBAction)handleForEdit:(id)sender {
    
    self.editBtnHandle((UIButton *) sender);
    
}

-(void)buttonHandle:(void (^)(UIButton *))block {

    self.deleBtnHandle = block;

}

- (void)editBtnHandle:(void (^)(UIButton *))Block1 deleBtnHandle:(void (^)(UIButton *))block2 {
    
    self.editBtnHandle = Block1;
    
    self.deleBtnHandle = block2;

}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
